$(function () {
    //常用jQuery对象
    var entity_datagrid = $("#entity_list");

    //==========================================================================
    //封装方法
    var methodObj = {

        //加载权限
        load: function () {
            $.messager.confirm("温馨提示", "请问确定要加载权限吗?", function (r) {
                if (r) {
                    $.get("/permission/load.do", function (data) {
                        if (data.success) {
                            $.messager.alert("温馨提示", data.msg, "info", function () {
                                entity_datagrid.datagrid("reload");
                            });
                        } else {
                            $.messager.alert("温馨提示", data.msg, "info");
                        }
                    }, "json");
                }
            });
        },

        //刷新页面
        reloadList: function () {
            entity_datagrid.datagrid("reload");
        }

    }


    //==========================================================================================
    //按钮绑定事件
    $("[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });

    //页面数据加载
    entity_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        url: "/permission/query.do",
        singleSelect: "true",
        pagination: true,
        rownumbers: true,
        columns: [[
            {field: 'name', title: '权限名', width: 100, align: "center"},
            {field: 'resource', title: '权限表达式', width: 100, align: "center"},
        ]],
        toolbar: "#tools"
    });

});

